<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/23
 * Time: 15:22
 */

namespace app\company\model;


class CsdList
{
    /*
     * 列表
     */
    public function getorderist($pageNum, $numPerPage,$param) {
        $field[] = 'dl.id';
        $field[] = 'o.order_sn';
        $field[] = 'dl.update_time';
        $field[] = 'dl.license_number';
        $field[] = 'dl.license_typename';
        $field[] = 'dl.user_name';
        $field[] = 'dl.license_nature';
        $field[] = 'dl.vehicle_brand';
        $field[] = 'dl.license_register_date';
        $field[] = 'dl.license_grant_date';
        $field[] = 'dl.vehicle_identification';
        // $field[] = 'dl.copy_license_number';
        // $field[] = 'dl.files_number';
        // $field[] = 'dl.inspection_record';
        $field[] = 'o.mobile';
        $field[] = 'o.license_type';
        $field[] = 'o.open_id';
        $list = db("order")
        ->alias('o')
        ->field($field)
        ->join('driving_license dl','o.order_id=dl.order_id','RIGHT')
        // ->where('is_delete',0)
        ->where('o.company_id',session('company.company_id'))
        ->where(function($query) use ($param){
            if(!empty($param['license_number'])){
                $query->where('dl.license_number','like','%'.$param['license_number'].'%');
            }
            if(!empty($param['license_type'])){
                $query->where('o.license_type','eq',$param['license_type']);
            }
            $query->where('o.mobile','like','%'.$param['mobile'].'%');
            $query->where('dl.user_name','like','%'.$param['user_name'].'%');
        })
        ->group('dl.vehicle_identification')
        ->order('dl.create_time desc')
        ->page($pageNum, $numPerPage)
        ->select();
        return $list;
    }
    /*
     * 数量
     */
    public function getorderount($param) {
        $count = db("order")
        ->alias('o')
        ->join('driving_license dl','o.order_id=dl.order_id','RIGHT')
        // ->where('is_delete',0)
        ->where('o.company_id',session('company.company_id'))
        ->where(function($query) use ($param){
            if(!empty($param['license_number'])){
                $query->where('dl.license_number','like','%'.$param['license_number'].'%');
            }
            if(!empty($param['license_type'])){
                $query->where('o.license_type','eq',$param['license_type']);
            }
            $query->where('o.mobile','like','%'.$param['mobile'].'%');
            $query->where('dl.user_name','like','%'.$param['user_name'].'%');
        })
        ->group('dl.vehicle_identification')
        ->count();
        return $count;
    }

    /**
     * 获取车辆数
     */
    public function get_car_number() {

        $count = db("order")
        ->alias('o')
        ->join('driving_license dl','o.order_id=dl.order_id','RIGHT')
        // ->where('is_delete',0)
        ->where('o.company_id',session('company.company_id'))
        ->group('dl.license_number')
        ->count();
        return $count;

    }
}